<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>编辑供应商 - TMS</title>
    <link rel="stylesheet" href="/view/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/view/frame/static/css/global.css?v=1.0">
    <link rel="stylesheet" href="/view/tms/static/css/add.css?v=1.0">
    <style>
        .continueAdd{display: inline-block}
    </style>
</head>

<body>
    <form class="layui-form" autocomplete="off">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>基本信息</legend>
        </fieldset>

        <div class="layui-fluid">
            <div class="layui-row">
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">主体属性</label>
                        <div class="layui-input-block">
                            <input type="radio" name="bodyType" lay-filter="bodyType" value="0" title="企业" checked>
                            <input type="radio" name="bodyType" lay-filter="bodyType" value="1" title="个体">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item layui-form-item--require">
                        <label class="layui-form-label"><span id="uscId">统一社会信用代码</span></label>
                        <div class="layui-input-block">
                            <input id="idNumberId" type="text" name="usc" class="layui-input" maxlength="18" lay-verify="required" hc-verify="usc">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item layui-form-item--require">
                        <label class="layui-form-label">供应商名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" class="layui-input" maxlength="255" lay-verify="required" hc-verify="companyRegex|companySize" hc-verify_field="供应商名称">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item layui-form-item--require">
                        <label class="layui-form-label">供应商简称</label>
                        <div class="layui-input-block">
                            <input type="text" name="nameShort"  maxlength="20" lay-verify="required" hc-verify="companyRegex|abbreviation" hc-verify_field="供应商简称" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm8">
                    <div class="layui-form-item layui-form-item--require" id="linkDistrict">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <div class="layui-col-sm3">
                                <div class="margin-right10">
                                    <select name="linkProvince" lay-filter="linkProvince">
                                    <option value="">请选择</option>
                                  </select>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="margin-right10">
                                    <select name="linkCity" lay-filter="linkCity">
                                    <option value="">请选择</option>
                                  </select>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div class="margin-right10">
                                    <select name="linkCounty" lay-filter="linkCounty">
                                    <option value="">请选择</option>
                                  </select>
                                </div>
                            </div>
                            <div class="layui-col-sm3">
                                <div>
                                    <select name="linkStreet" lay-filter="linkStreet">
                                    <option value="">请选择</option>
                                  </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="margin-left10">
                        <input type="hidden" name="linkmanAreaId">
                        <input type="text" name="linkmanAddress" lay-verify="required" placeholder="请输入详细地址" class="layui-input" maxlength="255">
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item layui-form-item--require">
                        <label class="layui-form-label">供应商类型</label>
                        <div class="layui-input-block">
                            <select name="typeDcode" lay-verify="required">
                              <option value="" selected="selected">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">英文名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="nameEn"  class="layui-input" maxlength="100" hc-verify="companyRegex|companySize" hc-verify_field="英文名称">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">网址</label>
                        <div class="layui-input-block">
                            <input type="text" name="weburl" placeholder="" class="layui-input" maxlength="100" hc-verify="url">
                        </div>
                    </div>
                </div>
            </div>

            <!-- 业务员信息 -->
            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务员姓名/手机</label>
                        <div class="layui-input-block">
                            <div class="layui-col-sm6">
                                <div class="margin-right10">
                                    <input type="text" name="salesmanName" placeholder="业务员姓名" class="layui-input" maxlength="20" hc-verify="userName" hc-verify_field="业务员姓名">
                                </div>
                            </div>
                            <div class="layui-col-sm6">
                                <input type="text" name="salesmanMobile" placeholder="业务员手机" class="layui-input" maxlength="20" hc-verify="mobile">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务员电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="salesmanTel" placeholder="" class="layui-input" maxlength="20" hc-verify="tele">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务员邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="salesmanEmail" placeholder="" class="layui-input" maxlength="100" hc-verify="email">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务员微信</label>
                        <div class="layui-input-block">
                            <input type="text" name="salesmanWechat" placeholder="" class="layui-input" maxlength="100" hc-verify="wechat">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务员QQ</label>
                        <div class="layui-input-block">
                            <input type="text" name="salesmanQq" placeholder="" class="layui-input" maxlength="20" hc-verify="qq">
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">使用公司</label>
                        <div class="layui-input-block" lay-filter="companyUsed"> 
                            <select name="companyUsedId" id="companyUsedList" lay-search lay-filter="companyUsedId" lay-search hc-data_url="/ucenter/centre/core/organization/all.shtml">
                                <option value="" selected>请选择</option>
                                <option value="" disabled>数据加载中...</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="status" lay-filter="status" id="status">
                                <option value="0" selected>草稿</option>
                                <option value="1">启用</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm8">   
                    <div class="layui-form-item">
                        <label class="layui-form-label">注意事项</label>
                        <div class="layui-input-block">
                            <textarea name="notes" placeholder="注意事项，0~300之间" class="layui-textarea" maxlength="300" hc-verify="remarkSize" style="min-height:50px;"></textarea>
                        </div>
                    </div>   
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-sm12">
                    <div class="layui-form-item">
                        <span class="form-txt" style="color: #f00">注：草稿状态，客户任何信息都能编辑，包括统一社会代码或身份证；但不能给草稿状态的客户下单。启用状态，统一社会代码／身份证不能编辑，其他信息可编辑，只有启用状态的客户，才能帮他们下单。</span>                       
                    </div>
                </div>
            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title">
            <legend>结算信息</legend>
        </fieldset>

        <div class="layui-fluid" style="margin-top:20px;">
            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">结算方式</label>
                        <div class="layui-input-block">
                            <select name="paymentTypeDcode">
                              <option value="" selected="selected">请选择</option>
                              <option value="0">现金</option>
                              <option value="30">30天</option>
                              <option value="45">45天</option>
                              <option value="60">60天</option>
                              <option value="90">90天</option>
                              <option value="120">120天</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">欠款金额上限(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="upperLimit" class="layui-input" maxlength="12" hc-verify="billionDecimals2" hc-verify_field="欠款金额上限(元)" hc-verify_min="0" hc-verify_max="999999999.99" placeholder="0~999999999.99">
                        </div>
                    </div>
                </div>
            </div>

            <!-- 结算信息财务人信息 -->
            <div class="layui-row">
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">财务姓名/手机</label>
                        <div class="layui-input-block">
                            <div class="layui-col-sm6">
                                <div class="margin-right10">
                                    <input type="text" name="financeName" placeholder="财务姓名" class="layui-input" maxlength="20" hc-verify="userName" hc-verify_field="财务姓名">
                                </div>
                            </div>
                            <div class="layui-col-sm6">
                                <input type="text" name="financeMobile" placeholder="财务手机" class="layui-input" maxlength="20" hc-verify="mobile">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">财务电话/邮箱</label>
                        <div class="layui-input-block">
                            <div class="layui-col-sm6">
                                <div class="margin-right10">
                                    <input type="text" name="financeTel" placeholder="财务电话" class="layui-input" maxlength="20" hc-verify="tele">
                                </div>
                            </div>
                            <div class="layui-col-sm6">
                                <input type="text" name="financeEmail" placeholder="财务邮箱" class="layui-input" maxlength="100" hc-verify="email">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">财务微信/QQ</label>
                        <div class="layui-input-block">
                            <div class="layui-col-sm6">
                                <div class="margin-right10">
                                    <input type="text" name="financeWechat" placeholder="财务微信" class="layui-input" maxlength="100" hc-verify="wechat">
                                </div>
                            </div>
                            <div class="layui-col-sm6">
                                <input type="text" name="financeQq" placeholder="财务QQ" class="layui-input" maxlength="20" hc-verify="qq">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 银行信息 -->
        <fieldset class="layui-elem-field layui-field-title">
            <legend>
                银行信息
                <span class="legend-btns">
                  <a class="layui-icon icon-add tableSSC" data-type="supplierSettlementChannelsAdd" data-func="callbackSSC(obj)">&#xe61f;</a>
                </span>
            </legend>
        </fieldset>
        <table id="tableListTP" lay-filter="tableSSC"></table>
        <input type="hidden" name="dataSSC">

        <!-- 保存按钮 -->
        <div id="buttonBar" class="layui-form-item button-bar">
            <div class="continueAdd"><input id="continue" name="continueAdd" type="checkbox" title="保存后继续添加" lay-skin="primary" checked></div>
            <input type="button" class="layui-btn layui-btn-normal" id="vsubmit" lay-submit lay-filter="submit" value="保存">
            <input type="button" class="layui-btn layui-btn-primary" id="vcancel" value="取消">
        </div>

    </form>
</body>
<script charset="utf-8" src="/view/frame/layui/layui.js"></script>
<script charset="utf-8" src="/view/frame/static/js/jquery.min.js?v=1.0"></script>
<script charset="utf-8" src="/view/frame/static/js/lang_zh_CN.js?v=1.0"></script>
<script charset="utf-8" src="/view/tms/static/js/tms_tab.js?v=1.0"></script>
<script charset="utf-8" src="/view/frame/static/js/layui.district_1.js?v=1.0"></script>
<script charset="utf-8" src="/view/tms/static/js/tms_index.js?v=1219"></script>
<!-- 工具库依赖 -->
<script charset="utf-8" src="/view/frame/static/js/errorCodeMap.js"></script>
<script charset="utf-8" src="/view/frame/static/js/HC.js?v=1.4"></script>
<script charset="utf-8" src="/view/tms/static/js/validator.js"></script>
<script charset="utf-8" src="/view/tms/static/js/bizUtil.js"></script>

<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">冻结</a>
</script>
<script type="text/html" id="channelTypeTpl">
    {{# if(d.channelType == 0){ }}
    <div>银行</div>
    {{# }else if(d.channelType == 1){ }}
    <div>支付宝</div>
    {{# }else if(d.channelType == 2){ }}
    <div>微信</div>
    {{# } }}
</script>
<script type="text/html" id="statusTpl">
    {{# if(d.status == 1){ }}
    <a lay-event="statusCancle" style="color:#1E9FFF;">激活</a> {{# }else{ }}
    <a lay-event="statusStart" style="color:#FF5722;">冻结</a> {{# } }}
</script>
<script>
    layui.use(['form', 'layer', 'layedit', 'laydate', 'table'], function() {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate,
            tmsTab = layui.tms_tab,
            table = layui.table,
            $ = layui.jquery;


        var $type = $.trim(getUrlParam('do'));
        var $idS = $.trim(getUrlParam('id'));
        var uscIs = true;
        bizUtil.layui.loadDataToSelect('#companyUsedList');
        bizUtil.init.initSelectData();

        if ($type == 'add') $('#linkDistrict').district(form);
        var supplierSettlementChannelsArr = [];

        //初始化供应商类型
        $('select[name="typeDcode"]').append(getSupplierCustomerList());
        form.render('select');

        //监听新增客户主体属性
        form.on('radio(bodyType)', function(data) {
            // console.log(data.elem); //得到radio原始DOM对象
            // console.log(data.value); //被点击的radio的value值
            if (data.value == 1) {
                $('#uscId').html('身份证');
                $('input[name="usc"]').attr('hc-verify', 'idNumber');

                //选中主体属性为个人时  客户类型默认选中车主
                $('select[name="typeDcode"]').val('553');
                form.render('select');
            } else {
                $('#uscId').html('统一社会信用代码');
                $('input[name="usc"]').attr('hc-verify', 'usc');

                $('select[name="typeDcode"]').val('');
                form.render('select');
            }

        });

        var tableActive = {
            supplierSettlementChannels: function(data, $type) {
                if ($type == 'detail') {
                    table.render({
                        data: data,
                        elem: '#tableListTP',
                        page: true,
                        limit: 5,
                        limits: [5, 10, 25, 50],
                        id: 'dataReloadTP',
                        cols: [
                            [{
                                field: 'channelType',
                                title: '渠道',
                                width: 100,
                                templet: '#channelTypeTpl',
                                align: 'center'
                            }, {
                                field: 'bankName',
                                title: '开户银行',
                                width: 150,
                                align: 'center'
                            }, {
                                field: 'bankBranchName',
                                title: '支行',
                                width: 150,
                                align: 'center'
                            }, {
                                field: 'accountName',
                                title: '账户名称/姓名',
                                width: 120,
                                align: 'center'
                            }, {
                                field: 'accountNo',
                                title: '账号',
                                width: 200,
                                align: 'center'
                            }, {
                                field: 'status',
                                title: '状态',
                                width: 100,
                                templet: '#statusTpl',
                                align: 'center'
                            }, {
                                field: 'remarks',
                                title: '备注',
                                width: 372
                            }]
                        ],
                    })
                } else {
                    table.render({
                        data: data,
                        elem: '#tableListTP',
                        page: true,
                        limit: 5,
                        limits: [5, 10, 25, 50],
                        id: 'dataReloadTP',
                        cols: [
                            [{
                                field: 'channelType',
                                title: '渠道',
                                width: 100,
                                templet: '#channelTypeTpl',
                                align: 'center'
                            }, {
                                field: 'bankName',
                                title: '开户银行',
                                width: 150,
                                align: 'center'
                            }, {
                                field: 'bankBranchName',
                                title: '支行',
                                width: 150,
                                align: 'center'
                            }, {
                                field: 'accountName',
                                title: '账户名称/姓名',
                                width: 120,
                                align: 'center'
                            }, {
                                field: 'accountNo',
                                title: '账号',
                                width: 200,
                                align: 'center'
                            }, {
                                field: 'status',
                                title: '状态',
                                width: 100,
                                templet: '#statusTpl',
                                align: 'center'
                            }, {
                                field: 'remarks',
                                title: '备注',
                                width: 251
                            }, {
                                align: 'center',
                                title: '操作',
                                toolbar: '#bar',
                                width: 120
                            }]
                        ],
                    })
                }

            }
        }

        if ($type == 'add') {
            //初始化统一信用代码，焦点事件失去时，通过统一信用代码获取公司详情
            $('input[name="usc"]').on('blur', function() {
                var $usc = $.trim($(this).val());
                var $uscType = $(this).attr('lay-verify');
                var $uscName = $uscType == 'usc' ? '企业' : '个人';
                uscIs = true;  
                if ($usc.length == 18) {
                    //获取企业/个人详情   
                                   
                    var $companyDetail = getCompanyByUsc($usc);
                    if ($companyDetail != null) {
                        $('input[name="name"]').val($companyDetail.coName);
                        $('input[name="nameShort"]').val($companyDetail.coNameShort);
                    }
                    var $verifyCompany = verifyCompanyByUsc($usc,2);
                    console.log($verifyCompany);
                    if(typeof $verifyCompany =='string'){
                        HCValidator.showTips($('input[name=usc]'),$verifyCompany);
                        uscIs = false;
                    }
                }
            })
        } else if($type == 'detail'){
            $('select[name=status]').append('<option value="3">停用</option>');
            form.render('select');          
              
        }else{

        }

        if ($type == 'edit' || $type == 'detail') {
            var $id = $.trim(getUrlParam('id'));
            if ($id != null && $id.length != 0) {
                $('input[name="id"]').val($id);
                $('.continueAdd').hide();
                $('input[name=continueAdd]').attr('checked',false);
                if ($type == 'detail') {
                    $('form input').prop('disabled', true).css({
                        'background': '#eee'
                    });
                    $('form select').prop('disabled', true).css({
                        'background': '#eee'
                    });
                    $('form textarea').prop('disabled', true).css({
                        'background': '#eee'
                    });
                    $('#buttonBar').hide();
                    $('a[data-func^="callback"]').hide();
                }

                //获取数据
                $.get('/ucenter/crm/supplier/supplier/getDetail.shtml?supplierId=' + $id, function(d) {
                    var $code = d.code,
                        $msg = d.msg,
                        $objects = d.objects;
                    if ($code === 'SUCCESS') {
                        //基本信息
                        $objects.bodyType == 0 ? $('#uscId').html('统一社会信用代码') : $('#uscId').html('身份证');
                        $objects.bodyType == 0 ? $('#idNumberId').attr('hc-verify','usc') : $('#idNumberId').attr('hc-verify','idNumber');

                        //如果状态为启用 则统一社会信用代码和状态都不可更改
                        if($objects.status == 1){
                            $('input[name="usc"]').prop('disabled', true).css({'background': '#eee'});

                            $('select[name="status"]').prop('disabled', true).css({'background': '#eee'});

                            $('input[name="bodyType"]').prop('disabled', true);
                        }

                        $('input[name="bodyType"]').each(function() {
                            if ($objects.bodyType == parseInt($(this).val())) {
                                $(this).prop('checked', true);

                            } else {
                                $(this).prop('checked', false);

                            }
                        });
                        $('select[name=status]').val($objects.status); 
                        $('input[name=nameShort]').val($objects.nameShort);
                        $('input[name=usc]').val($objects.usc);
                        $('input[name=name]').val($objects.name);
                        $('input[name=nameEn]').val($objects.nameEn);
                        $('input[name=weburl]').val($objects.weburl);
                        $objects.linkmanAreaId != null ? $('input[name="linkmanAreaId"]').val($objects.linkmanAreaId) : '';
                        $objects.linkmanAreaId != null ? (
                            $type == 'detail' ? $('#linkDistrict').district(form, $objects.linkmanAreaId, 0) : $('#linkDistrict').district(form, $objects.linkmanAreaId)
                        ) : $('#linkDistrict').district(form);
                        $('input[name=linkmanAddress]').val($objects.linkmanAddress);
                        $('input[name=salesmanName]').val($objects.salesmanName);
                        $('input[name=salesmanMobile]').val($objects.salesmanMobile);
                        $('input[name=salesmanTel]').val($objects.salesmanTel);
                        $('input[name=salesmanWechat]').val($objects.salesmanWechat);
                        $('input[name=salesmanQq]').val($objects.salesmanQq);
                        $('input[name=salesmanEmail]').val($objects.salesmanEmail);
                        $('textarea[name=remarks]').val($objects.remarks);
                        $('textarea[name=notes]').val($objects.notes);

                        $objects.companyUsedId != null ? $('select[name="companyUsedId"]').val($objects.companyUsedId) : '';
                        $objects.companyUsedId != null ? $objects.companyUsedId=$objects.companyUsedId : $objects.companyUsedId='';
                        $.when($('#companyUsedList').data('ajaxDeferred')).done(function(){
                            $('#companyUsedList').val($objects.companyUsedId)
                            form.render('select');
                        })

                        $objects.typeDcode != null ? $('select[name="typeDcode"]').val($objects.typeDcode) : '';

                        // //结算信息 
                        var $supplierSettlement = $objects.supplierSettlement;
                        $('input[name=upperLimit]').val($supplierSettlement.upperLimit);
                        $supplierSettlement.paymentTypeDcode != null ? $('select[name=paymentTypeDcode]').val($supplierSettlement.paymentTypeDcode) : '';
                        $('input[name=financeName]').val($supplierSettlement.financeName);
                        $('input[name=financeMobile]').val($supplierSettlement.financeMobile);
                        $('input[name=financeTel]').val($supplierSettlement.financeTel);
                        $('input[name=financeWechat]').val($supplierSettlement.financeWechat);
                        $('input[name=financeQq]').val($supplierSettlement.financeQq);
                        $('input[name=financeEmail]').val($supplierSettlement.financeEmail);
                        //结算银行信息列表
                        supplierSettlementChannelsArr = $objects.supplierSettlementChannels;
                        tableActive.supplierSettlementChannels(supplierSettlementChannelsArr, $type);

                        form.render('radio');
                        form.render('select');
                        form.render('checkbox');
                        
                    } else {
                        parent.layer.alert('数据异常');
                        return false;
                    }
                }, 'json');
            } else {
                parent.layer.alert('请不要使用非法参数！', {
                    yes: function() {
                        parent.layer.closeAll();
                    }
                });
            }
        }
        table.on('tool(tableSSC)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象 
            
            data.$id != null ? data.$id = data.$id : data.$id = (new Date()).getTime();
            var $data = JSON.stringify(data);
            $('input[name=dataSSC]').attr('data-func', 'callB(' + $data + ')');
            var $url = './supplierSettlementChannels.html?do=edit&id=' + data.$id + '&channelType=' + data.channelType + '&bankName=' + escape(data.bankName);
            if (layEvent === 'edit') { //编辑 
                parent.layer.open({
                    type: 2,
                    title: '编辑银行',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['900px', '500px'],
                    content: $url,
                    success: function(layero, index) {},
                    btn: ['确定', '关闭'],
                    yes: function(index, layero) {
                        $(layero.find('iframe')[0].contentWindow.document).find('#vsubmit').click();
                        var cllBack = $('.tableSSC').attr('data-func')
                        var Fun = eval(cllBack);
                        var objs = Fun;
                        obj.update(objs);
                    }
                });
            } else if (layEvent === 'del') {
                if (data.status == 1) {
                    $(this).html('激活');
                    data.status = 3;
                    obj.update(data);
                } else if (data.status == 3) {
                    $(this).html('冻结');
                    data.status = 1;
                    obj.update(data)
                }
            }
        });

        function callbackSSC(obj) {
            if (obj == undefined) return
            if (obj.$id) {
                parent.layer.closeAll();
                return obj
            }
            obj.$id = (new Date()).getTime();
            obj.status = 1;
            supplierSettlementChannelsArr.unshift(obj);
            tableActive.supplierSettlementChannels(supplierSettlementChannelsArr);
            parent.layer.closeAll();
            $('.tableSSC').attr('data-func', 'callbackSSC()');
            if (obj.conAdd == 1) {
                active.supplierSettlementChannelsAdd();
                return
            }
        }
        var active = {
            //新增银行
            supplierSettlementChannelsAdd: function() {
                parent.layer.open({
                    type: 2,
                    title: '添加银行',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['950px', '550px'],
                    content: './supplierSettlementChannels.html?do=add',
                    success: function(layero, index) {},
                    btn: ['确定', '关闭'],
                    yes: function(index, layero) {
                        $(layero.find('iframe')[0].contentWindow.document).find('#vsubmit').click();
                        var cllBack = $('.tableSSC').attr('data-func')
                        var Fun = eval(cllBack);
                        Fun;
                    }
                });
            },

        };

        //给新增按钮添加事件
        $('.legend-btns a').on('click', function() {
            active.supplierSettlementChannelsAdd();
        });

        //监听提交
        if ($type == 'edit' || $type == 'add') {
            form.on('submit(submit)', function(data) {
                $("#vsubmit").blur();
                if (!bizUtil.validator.verifyContainer($('form'))) {
                    return false;
                }
                if(!uscIs){
                    bizUtil.validator.showElementVerifyError($('input[name=usc]'),'供货商已存在');
                    return false;
                }
                //城市ID
                var $index1 = $('#linkDistrict select').not(':disabled').length - 1,
                    $indexVal1 = $('#linkDistrict select').eq($index1).val();
                $indexVal1.length > 0 ? $('input[name="linkmanAreaId"]').val($indexVal1) : '';
                if ($('input[name="linkmanAreaId"]').val().length == 0) {
                    parent.layer.msg('请选择详细地址的城市');
                    return false;
                }

                supplierSettlementChannelsArr.forEach(function(item, index, input) {
                    delete(item.$id)
                    delete(item.conAdd)
                    delete(item.LAY_TABLE_INDEX)
                })

                var $linkmanAreaId = $('input[name="linkmanAreaId"]').val().length > 0 ? parseInt($.trim($('input[name="linkmanAreaId"]').val())) : '';
                //数据源       
                var $saveData = {
                    bodyType: parseInt($.trim(data.field.bodyType)),
                    linkmanAddress: $.trim(data.field.linkmanAddress),
                    linkmanAreaId: $linkmanAreaId,
                    name: $.trim(data.field.name),
                    nameEn: $.trim(data.field.nameEn),
                    nameShort: $.trim(data.field.nameShort),
                    status: parseInt($.trim(data.field.status)),
                    remarks: $.trim(data.field.remarks),
                    notes: $.trim(data.field.notes),
                    typeDcode: $.trim(data.field.typeDcode),
                    companyUsedId: $.trim(data.field.companyUsedId),

                    salesmanEmail: $.trim(data.field.salesmanEmail),
                    salesmanMobile: $.trim(data.field.salesmanMobile),
                    salesmanName: $.trim(data.field.salesmanName),
                    salesmanQq: $.trim(data.field.salesmanQq),
                    salesmanTel: $.trim(data.field.salesmanTel),
                    salesmanWechat: $.trim(data.field.salesmanWechat),

                    // status: 1,
                    usc: $.trim(data.field.usc),
                    weburl: $.trim(data.field.weburl),
                    supplierSettlementChannels: supplierSettlementChannelsArr,
                    supplierSettlement: {
                        upperLimit: parseFloat($.trim(data.field.upperLimit)),
                        financeEmail: $.trim(data.field.financeEmail),
                        financeMobile: $.trim(data.field.financeMobile),
                        financeName: $.trim(data.field.financeName),
                        financeQq: $.trim(data.field.financeQq),
                        financeTel: $.trim(data.field.financeTel),
                        financeWechat: $.trim(data.field.financeWechat),
                        paymentTypeDcode: parseInt($.trim(data.field.paymentTypeDcode))
                    }
                };
                var $url, $method;
                if ($type == 'edit') {
                    $url = '/ucenter/crm/supplier/supplier/' + $idS + '.shtml';
                    $method = 'PUT';
                } else if ($type == 'add') {
                    $url = '/ucenter/crm/supplier/supplier/add.shtml';
                    $method = 'POST';
                }
                console.log($saveData);
                //保存数据，调用接口
                // $.ajax({
                //     type: $method,
                //     url: $url,
                //     dataType: "json",
                //     contentType: "application/json",
                //     data: JSON.stringify($saveData),
                //     success: function(d) {
                //         var $code = d.code,
                //             $msg = d.msg,
                //             $objects = d.objects;

                //         if ($code === 'SUCCESS') {
                //             parent.layer.alert("保存成功", {
                //                 closeBtn: 0,
                //                 yes: function(index){
                //                     parent.layer.close(index);
                //                     if($("#continue").is(":checked")){  //保存后继续新增
                //                     $(window.parent['f1'].document).find('.btn-search').click();
                //                     window.location.reload();
                //                     }else{
                //                     $(window.parent['f1'].document).find('.btn-search').click();
                //                     tmsTab.del($(window.parent.document).find('.layui-tab-title li.layui-this').attr('lay-id'));
                //                     }
                //                 }
                //             });
                //         } else {
                //             parent.layer.alert('保存信息失败，请重新填写！');
                //         }
                //     }
                // });
                                //保存数据，调用接口
                HC.ajax[$method.toLowerCase()]({
                    url: $url,
                    data: JSON.stringify($saveData),
                    success: function(d) {
                        parent.layer.alert('保存成功！', {
                            yes: function(index) {
                                //关闭窗口
                                parent.layer.close(index);
                                if($("#continue").is(":checked")){
                                    $(window.parent['f1'].document).find('.btn-search').click();
                                    window.location.reload();
                                }else{
                                    parent.layer.closeAll();
                                    //获取当前框架ID并刷新
                                    bizUtil.frame.refreshCurrentFrame();
                                    bizUtil.frame.refreshListFrame();
                                    bizUtil.frame.closeCurrentIframeTab(window.parent);  
                                }
                                                          
                            }
                        });
                    }
                });
                return false;
            });

            //取消按钮事件
            $('#vcancel').on('click', function() {
                bizUtil.frame.closeCurrentIframeTab(window.parent);
            });
        }
    });
</script>

</html>